package com.shop2cn.iapi.promotion.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.promotion.parameter.GetPromotionProductByIdReq;
import com.shop2cn.iapi.promotion.parameter.GetPromotionProductByIdResp;
import com.shop2cn.iapi.promotion.serivce.GetPromotionProductByIdCall;
import com.shop2cn.iapi.promotion.serivce.PromotionInfoVerify;
import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JSellerPromotionCallService;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.compare.AssertHelper;
/**
*根据促销ID、买手ID获取促销商品信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetPromotionProductById{
	private static GetPromotionProductByIdReq getpromotionproductbyidBean;
	private static GetPromotionProductByIdCall getpromotionproductbyidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据促销ID、买手ID获取促销商品信息");
	}

	@Before
	public void caseUp() {
		getpromotionproductbyidBean=new GetPromotionProductByIdReq();
		getpromotionproductbyidCall=new GetPromotionProductByIdCall();
	}    

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpromotionproductbyidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPromotionProductById_001() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
//			getpromotionproductbyidBean.setSellerId(94);
//			getpromotionproductbyidBean.setPromotionId(721);
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			GetPromotionProductByIdResp resp = getpromotionproductbyidCall.getData();
			
			Logger.verifyEquals(2, resp.getProductJoinMethod(), "验证返回Code");

			List<String> productIds = resp.getProductIds();
			for(int i=0;i<productIds.size();i++)
			{
				Logger.verifyEquals(createpromotionBean.getProductIdList().get(i), productIds.get(i), "验证返回ProductId");

			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProductById_002() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-活动已取消");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.EndAllEnablePromotion(sellerid);
			
			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetPromotionProductById_003() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-活动未开始");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(promotionId);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetPromotionProductById_004() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-新老接口对比-待完善");
		try {
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_005() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-sellerId空");
		try {

			getpromotionproductbyidBean.setPromotionId(1);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_006() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-promotionId空");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			

			getpromotionproductbyidBean.setSellerId(sellerid);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetPromotionProductById_007() {
		Logger.start(true,"根据促销ID、买手ID获取促销商品信息-sellerid与promotionId不一致");
		try {
			//TODO 补全case代码
			int sellerid = Integer.valueOf(EnvSetup.getData("couponSellerId"));			

			getpromotionproductbyidBean.setSellerId(sellerid);
			getpromotionproductbyidBean.setPromotionId(54545);
			
			getpromotionproductbyidCall.setData(getpromotionproductbyidBean);
			getpromotionproductbyidCall.callService();
			
			Logger.verifyEquals("200", getpromotionproductbyidCall.getCode(), "验证返回Code");
			Logger.verifyEquals(null, getpromotionproductbyidCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}